<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
            构造函数
                1. let obj = {}
                2. obj.__proto__ = Person.prototype
                3. obj = Person.call(obj)
                4. 返回 obj

            prototype json
            
            let p = new Person('test');

            p.prototype -> Person -> Function -> Object

            继承
            this, call, apply
        */
        
        let Animal = function() {
            this.age = 18
        }
        Animal.sleep = function() {
            console.log(
                this.name + '正在睡觉'
            )
        }

        let Person = function(name) {
            Animal.apply(this, arguments)
            this.name = name || '石兴龙'
        }

        var TempFn = function() {
            this.constructor = Person
        }
        TempFn.prototype = Animal.prototype

        Person.prototype = new TempFn();

        Person.prototype.eat = function () {
            console.log(
                this.name + '正在吃饭'
            )
        }

        let p = new Person('test')
        console.log(
            p
        )

        let o = {
            name: '18',
            length: 1
        }

        var a = []
        a.push(1,2,3,4)

        a.push.call(o, '1', 2,3,4,5)
        console.log(o, a)

        

        console.log(
            a.push === Array.prototype.push
        )

    </script>
</body>
</html>